package com.restaurant.serviceimpl;

import java.util.List;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import com.restaurant.domain.Currencytype;
import com.restaurant.service.CurrencytypeService;

public class CurrencytypeServiceImpl implements CurrencytypeService {

   private HibernateTemplate hibernateTemplate;

   @Autowired
   public void setSessionFactory(SessionFactory sessionFactory){
       this.hibernateTemplate = new HibernateTemplate(sessionFactory);
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Currencytype addOrModify( Currencytype objCurrencytype ) {
       return ( Currencytype ) hibernateTemplate.merge( objCurrencytype );
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Currencytype deleteRecord( Currencytype objCurrencytype ) {
       hibernateTemplate.delete( objCurrencytype );
       return objCurrencytype;
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Currencytype modifyRecord( Currencytype objCurrencytype ) {
       return ( Currencytype ) hibernateTemplate.merge( objCurrencytype );
   }

   @SuppressWarnings("unchecked")
   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public List<Currencytype> loadAll() {
       return (List<Currencytype>)hibernateTemplate.findByNamedQuery( "Currencytype.findAll");
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Currencytype loadByPrimaryKey( Long primaryKey ) {
       return (Currencytype) hibernateTemplate.get( Currencytype.class, primaryKey );
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Currencytype deleteByPrimaryKey( Long primaryKey ) {
       return deleteRecord(loadByPrimaryKey(primaryKey));
   }

   @SuppressWarnings("unchecked")
   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public List<Currencytype> loadByHql(String query) {
       return ( List<Currencytype> ) hibernateTemplate.find( query );
   }
}